package br.com.linkideias.model.bean;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
public class QualidadeProfissional {
	private Integer codigo;
	private String nome;
	private List<Aluno> alunos = new ArrayList<Aluno>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getCodigo() {
		return codigo;
	}
	public void setCodigo(Integer codigo) {
		this.codigo = codigo;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	
	//@ManyToMany(cascade = { CascadeType.ALL }, fetch=FetchType.LAZY)
	@ManyToMany(cascade = { CascadeType.ALL }, fetch=FetchType.LAZY)
	@JoinTable(name="alunoQualidadeProfissional",
			joinColumns={@JoinColumn(name="qualidadeProfissional_codigo")},
			inverseJoinColumns={@JoinColumn(name="aluno_codigo")})
	public List<Aluno> getAlunos() {
		return alunos;
	}
	public void setAlunos(List<Aluno> alunos) {
		this.alunos = alunos;
	}
	@Transient
	public boolean isValido() {
		if(nome != null && nome.length() > 2)
			return true;
		return false;
	}
}
